//
//  CLNavigationController.m
//  chanlin
//
//  Created by Ryan on 14-10-31.
//  Copyright (c) 2014年 chanlin. All rights reserved.
//

#import "CLNavigationController.h"
#import "CLBaseViewController.h"
#import "CLPushAnimatedRight.h"
#import "CLPopPanAction.h"

@interface CLNavigationController()


@property (nonatomic,assign) Protocol *basePop;

@end

@implementation CLNavigationController

- (instancetype)init{
    self=[super init];
    if(self){
        [self setNavigationBarHidden:YES animated:NO];
    }
    return self;
}

- (instancetype)initWithRootViewController:(UIViewController *)rootViewController{
    self=[super initWithRootViewController:rootViewController];
    if(self){
        [self setNavigationBarHidden:YES animated:NO];
    }
    return self;
}

- (void)viewDidLoad{
   // id<CLPopPanAction>
    //id<CLPopPanAction>
    self.basePop=NSProtocolFromString(@"CLPopPanAction");

    self.delegate=self;
    self.panGesture=[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panAction:)];
    [self.view addGestureRecognizer:self.panGesture];
    self.panGesture.delegate=self;
}

- (void)panAction:(UIPanGestureRecognizer *)recognizer{
    
    [((CLBaseViewController *)self.topViewController).dispatchObj doPan:recognizer];
//    if(((CLBaseViewController *)self.topViewController).pushType==1){
//        [[CLPushAnimatedRight sharedInstance] doPan:recognizer];
//    }else if(((CLBaseViewController *)self.topViewController).pushType==2){
//        
//    }
}

- (BOOL)gestureRecognizerShouldBegin:(UIPanGestureRecognizer *)gestureRecognizer{
    CGPoint p=[gestureRecognizer velocityInView:self.view];
    
    return fabsf(p.y/p.x)<0.5;
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
  
    
    if ([touch.view isKindOfClass:[UISlider class]] || [touch.view isKindOfClass:[UISwitch class]]) {
        return NO;
    }
   // NSLog(@"%@---%d",self.topViewController,[self.topViewController conformsToProtocol:self.basePop]);
//    NSLog(@"%@-%@-%@-%@-",NSStringFromClass([touch.view class]),
//          NSStringFromClass([touch.view.superview class]),
//          NSStringFromClass([touch.view.superview.superview class]),
//          NSStringFromClass([touch.view.superview.superview.superview class]));
    return [self.topViewController isKindOfClass:[CLBaseViewController class]]&&
    [((CLBaseViewController *)self.topViewController) showPopAction] && (![touch.view isKindOfClass:[UISlider class]]);
        
}

- (BOOL)shouldAutorotate{
    return [((CLBaseViewController *)self.topViewController) __shouldAutorotate];
    
}

- (NSUInteger)supportedInterfaceOrientations{
    return [((CLBaseViewController *)self.topViewController) __supportedInterfaceOrientations];
}

//- (id<UIViewControllerInteractiveTransitioning>)navigationController:(UINavigationController *)navigationController
//                         interactionControllerForAnimationController:(id<UIViewControllerAnimatedTransitioning>)animationController{
//    NSLog(@"----------111");
//    return nil;
//}
//
//- (id <UIViewControllerAnimatedTransitioning>)navigationController:(UINavigationController *)navigationController
//                                   animationControllerForOperation:(UINavigationControllerOperation)operation
//                                                fromViewController:(UIViewController *)fromVC
//                                                  toViewController:(UIViewController *)toVC{
//    NSLog(@"----------111");
//    return nil;
//
//    
//}
@end
